package com.dayuanit.dy15.atm.exception;

import com.dayuanit.dy15.atm.dto.ResponseDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author echo
 * @date 2020/5/23 - 12:23
 */

//异常统一处理
@ControllerAdvice
@Slf4j //打印日志
public class ExceptionHandler {


    @org.springframework.web.bind.annotation.ExceptionHandler(BizException.class)
    @ResponseBody
    public ResponseDTO bizException(BizException b){
        log.error(b.getMessage());
        b.printStackTrace();
        return ResponseDTO.error().message(b.getMessage());
    }

    @ResponseBody
    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    public ResponseDTO error(Exception e){
        log.error(e.getMessage());
        e.printStackTrace();
        return ResponseDTO.error().message("联系管理员...");
    }
}
